{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "d92b1e17-23db-49ac-accc-ab76b373359b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(614, 5)\n",
      "(614, 4)\n",
      "20/20 [==============================] - 0s 2ms/step - loss: 0.1376 - accuracy: 0.9593\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[0.1376396268606186, 0.9592834115028381]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "from autopilot_data import AutopilotData\n",
    "import sys\n",
    "import numpy as np\n",
    "\n",
    "#动作常量\n",
    "ACTION_UP = 0\n",
    "ACTION_DOWN = 1\n",
    "ACTION_LEFT = 2\n",
    "ACTION_RIGHT = 3\n",
    "\n",
    "#加载自动驾驶模型\n",
    "model = tf.keras.models.load_model(sys.path[0]+'/model.h5')\n",
    "\n",
    "ad = AutopilotData()\n",
    "x_train,y_train = ad.load_data()\n",
    "\n",
    "print(x_train.shape)\n",
    "print(y_train.shape)\n",
    "\n",
    "x_train = x_train / 500.0\n",
    "y_train = y_train / 1.0\n",
    "\n",
    "model.evaluate(x_train, y_train, batch_size=None, verbose=1, sample_weight=None, steps=None,callbacks=None, max_queue_size=10, workers=1, use_multiprocessing=False,return_dict=False)\n",
    "# for i in range(len(x_train)):\n",
    "#     dists = np.array([x_train[i]],np.float64)\n",
    "#     y = model.predict(dists)\n",
    "#     print(np.round(y,2),y_train[i])\n",
    "\n",
    "# #手动模拟距离数据\n",
    "# dists = np.array([[0,30,60,30,0]],np.float64)\n",
    "# dists = dists / 500.0\n",
    "# y = model.predict(dists)\n",
    "# action = np.argmax(y)\n",
    "# # 执行动作\n",
    "# if action == ACTION_UP:\n",
    "#     print (\"up\")\n",
    "# elif action == ACTION_DOWN:\n",
    "#     print (\"down\")\n",
    "# elif action == ACTION_LEFT:\n",
    "#     print (\"left\")\n",
    "# elif action == ACTION_RIGHT:\n",
    "#     print (\"right\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e222c963-72f9-4afc-9e61-438c03102a0e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7321727f-cd45-4b80-b088-5ea9aefb01ed",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "adeab07c-cc1f-4882-a6fa-ab233f6085cb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.15"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
